{	Problem: http://codeforces.ru/problemset/problem/24/B
	Verdict: Accepted
}
{$R+,S+,Q+,I+,C+,M+,O-}
uses SysUtils;
const b:array[1..10] of longint=(25, 18, 15, 12, 10, 8, 6, 4, 2, 1);
var i,n,k,j,m,c,index,g,pn:longint; h,v:array[1..60] of longint; f:boolean; t:string; p:array[1..60] of string; a:array[1..60,0..60] of longint;
begin
fillchar(a,sizeof(a),0);
readln(n);
c:=0;
for i:=1 to n do begin
  readln(k);
  for j:=1 to k do begin
    readln(t);
    f:=false;
    for m:=1 to c do
      if p[m]=t then begin
        f:=true;
        index:=m;
        break;
      end;
    if not f then begin
      inc(c);
      p[c]:=t;
      index:=c;
    end;
    inc(a[index][j]);
    if j<=10 then inc(a[index][0],b[j]);
  end;
end;
m:=1;
k:=1;
h[1]:=1;
for i:=2 to c do begin
  if a[i][0]>a[m][0] then begin
    k:=1;
    h[1]:=i;
    m:=i;
  end else
  if a[i][0]=a[m][0] then begin
    inc(k);
    h[k]:=i;
  end;
end;
pn:=1;
while k>1 do begin
  g:=1;
  v[1]:=h[1];
  m:=1;
  for i:=2 to k do begin
    if a[h[i]][pn]>a[h[m]][pn] then begin
      g:=1;
      v[1]:=h[i];
      m:=i;
    end else
    if a[h[i]][pn]=a[h[m]][pn] then begin
      inc(g);
      v[g]:=h[i];
    end;
  end;
  h:=v;
  k:=g;
  inc(pn);
end;
writeln(p[h[1]]);
m:=1;
k:=1;
h[1]:=1;
for i:=2 to c do begin
  if a[i][1]>a[m][1] then begin
    k:=1;
    h[1]:=i;
    m:=i;
  end else
  if a[i][1]=a[m][1] then begin
    inc(k);
    h[k]:=i;
  end;
end;
m:=1;
g:=1;
v[1]:=h[1];
for i:=2 to k do begin
  if a[h[i]][0]>a[h[m]][0] then begin
    m:=i;
    v[1]:=h[i];
    g:=1;
  end else
  if a[h[i]][0]=a[h[m]][0] then begin
    inc(g);
    v[g]:=h[i];
  end;
end;
h:=v;
k:=g;
pn:=2;
while k>1 do begin
  g:=1;
  v[1]:=h[1];
  m:=1;
  for i:=2 to k do begin
    if a[h[i]][pn]>a[h[m]][pn] then begin
      g:=1;
      v[1]:=h[i];
      m:=i;
    end else
    if a[h[i]][pn]=a[h[m]][pn] then begin
      inc(g);
      v[g]:=h[i];
    end;
  end;
  h:=v;
  k:=g;
  inc(pn);
end;
writeln(p[h[1]]);
end.